package com.k52group.vn.micromarket;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.k52group.vn.micromarket.adapter.HitAdapter;
import com.k52group.vn.micromarket.classes.Profile;
import com.k52group.vn.micromarket.utils.Constant;
import com.k52group.vn.micromarket.utils.Utils;

public class HitListActivity extends Activity {
	private ListView lv;
	private List<Profile> list = new ArrayList<Profile>();
	Profile profile = new Profile();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hit);

		String data_user = Utils.getData(Constant.USER, this);
		profile = new Gson().fromJson(data_user, Profile.class);

		lv = (ListView) findViewById(R.id.listView1);
		lv.setVisibility(View.GONE);
		String data = getIntent().getStringExtra("data");
		list = new Gson().fromJson(data, new TypeToken<ArrayList<Profile>>() {
		}.getType());
		if (list == null)
			list = new ArrayList<Profile>();

		List<Profile> data2 = new ArrayList<Profile>();
		for (Profile item : list) {
			if (!item.getDistance(HitListActivity.this).equals(""))
				data2.add(item);
		}
		list = data2;
		HitAdapter adapter = new HitAdapter(this, list);
		// if (profile.getUserId() == 0)
		// adapter.setGuest(true);

		lv.setAdapter(adapter);
		if (list.size() > 0)
			lv.setVisibility(View.VISIBLE);
		else
			Toast.makeText(this, "Empty !", Toast.LENGTH_SHORT).show();
	}
}
